﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Custom="http://schemas.microsoft.com/wpf/2008/toolkit">
	<!-- Resource dictionary entries should be defined here. -->
    <Style x:Key="DataGridColumnEditingStyle" TargetType="{x:Type TextBox}" >
        <Setter Property="Background" Value="#FFCBDAC5"/>
    </Style>
    <Style x:Key="DataGridStyle" TargetType="{x:Type Custom:DataGrid}">
		<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
		<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
		<Setter Property="BorderBrush" Value="#FF688CAF"/>
		<Setter Property="BorderThickness" Value="1,1,1,1"/>
		<Setter Property="RowDetailsVisibilityMode" Value="VisibleWhenSelected"/>
		<Setter Property="ScrollViewer.CanContentScroll" Value="True"/>
		<Setter Value="{DynamicResource DataGridControlTemplate}" Property="Template"/>
		<Setter Property="RowStyle" Value="{DynamicResource RowStyle}"/>
		<Setter Property="CellStyle" Value="{DynamicResource DataGridCellStyle}"/>
		<Style.Triggers>
			<Trigger Property="IsGrouping" Value="True">
				<Setter Property="ScrollViewer.CanContentScroll" Value="False"/>
			</Trigger>
		</Style.Triggers>
	</Style>
	<ControlTemplate x:Key="DataGridControlTemplate" TargetType="{x:Type Custom:DataGrid}">
		<Border SnapsToDevicePixels="True" Background="{DynamicResource BrushControlBackgroundLight}" BorderBrush="{DynamicResource ImpassiveColor4}" BorderThickness="{DynamicResource ThicknessSize_1}" CornerRadius="{DynamicResource CornerRadiusSmall}" Padding="{TemplateBinding Padding}">
			<ScrollViewer Template="{DynamicResource DataGridScrollViewerControlTemplate}" x:Name="DG_ScrollViewer" Style="{DynamicResource ScrollViewerListViewStyle}" Focusable="False">
				<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
			</ScrollViewer>
		</Border>
	</ControlTemplate>
	<ControlTemplate x:Key="DataGridScrollViewerControlTemplate" TargetType="{x:Type ScrollViewer}">
		<Grid>
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="*"/>
				<RowDefinition Height="Auto"/>
			</Grid.RowDefinitions>
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto"/>
				<ColumnDefinition Width="*"/>
				<ColumnDefinition Width="Auto"/>
			</Grid.ColumnDefinitions>
			<Button Width="{Binding Path=CellsPanelHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:DataGrid}}}" Focusable="False">
				<Button.Visibility>
					<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:DataGrid}}">
						<Binding.ConverterParameter>
							<Custom:DataGridHeadersVisibility>All</Custom:DataGridHeadersVisibility>
						</Binding.ConverterParameter>
					</Binding>
				</Button.Visibility>
				<Button.Template>
					<ControlTemplate TargetType="{x:Type Button}">
						<Grid>
							<Rectangle Fill="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" x:Name="Border" SnapsToDevicePixels="True"/>
							<Polygon Fill="#FF000000" Stretch="Uniform" HorizontalAlignment="Right" Margin="8,8,3,3" x:Name="Arrow" VerticalAlignment="Bottom" Opacity="0.15" Points="0,10 10,10 10,0"/>
						</Grid>
						<ControlTemplate.Triggers>
							<Trigger Property="IsMouseOver" Value="True">
								<Setter Property="Stroke" TargetName="Border" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
							</Trigger>
							<Trigger Property="IsPressed" Value="True">
								<Setter Property="Fill" TargetName="Border" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
							</Trigger>
							<Trigger Property="IsEnabled" Value="False">
								<Setter Property="Visibility" TargetName="Arrow" Value="Collapsed"/>
							</Trigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Button.Template>
				<Button.Command>
					<RoutedCommand/>
				</Button.Command>
			</Button>
			<Custom:DataGridColumnHeadersPresenter x:Name="PART_ColumnHeadersPresenter" Style="{DynamicResource DataGridColumnHeadersPresenterStyle}" Grid.Column="1">
				<Custom:DataGridColumnHeadersPresenter.Visibility>
					<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:DataGrid}}">
						<Binding.ConverterParameter>
							<Custom:DataGridHeadersVisibility>Column</Custom:DataGridHeadersVisibility>
						</Binding.ConverterParameter>
					</Binding>
				</Custom:DataGridColumnHeadersPresenter.Visibility>
			</Custom:DataGridColumnHeadersPresenter>
			<ScrollContentPresenter x:Name="PART_ScrollContentPresenter" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" Grid.ColumnSpan="2" Grid.Row="1" CanContentScroll="{TemplateBinding CanContentScroll}" CanHorizontallyScroll="False" CanVerticallyScroll="False"/>
			<ScrollBar x:Name="PART_VerticalScrollBar" Style="{DynamicResource ScrollBarStyle}" Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" Grid.Column="2" Grid.Row="1" Orientation="Vertical" ViewportSize="{TemplateBinding ViewportHeight}" Maximum="{TemplateBinding ScrollableHeight}" Value="{Binding Path=VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"/>
			<Grid Grid.Column="1" Grid.Row="2">
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="{Binding Path=NonFrozenColumnsViewportHorizontalOffset, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:DataGrid}}}"/>
					<ColumnDefinition Width="*"/>
				</Grid.ColumnDefinitions>
				<ScrollBar x:Name="PART_HorizontalScrollBar" Style="{DynamicResource ScrollBarStyle}" Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" Grid.Column="1" Orientation="Horizontal" ViewportSize="{TemplateBinding ViewportWidth}" Maximum="{TemplateBinding ScrollableWidth}" Value="{Binding Path=HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"/>
			</Grid>
		</Grid>
	</ControlTemplate>
	<Style x:Key="DataGridColumnHeadersPresenterStyle" TargetType="{x:Type Custom:DataGridColumnHeadersPresenter}">
		<Setter Value="{DynamicResource DataGridColumnHeadersPresenterControlTemplate}" Property="Template"/>
	</Style>
	<ControlTemplate x:Key="DataGridColumnHeadersPresenterControlTemplate" TargetType="{x:Type Custom:DataGridColumnHeadersPresenter}">
		<Grid>
			<Custom:DataGridColumnHeader Style="{DynamicResource DataGridColumnHeaderStyle}" IsHitTestVisible="False"/>
			<ItemsPresenter/>
		</Grid>
	</ControlTemplate>
	<Style x:Key="DataGridColumnHeaderStyle" TargetType="{x:Type Custom:DataGridColumnHeader}">
		<Setter Property="VerticalContentAlignment" Value="Center"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type Custom:DataGridColumnHeader}">
					<Grid>
						<Custom:DataGridHeaderBorder Background="#00000000" Padding="{TemplateBinding Padding}" IsClickable="{TemplateBinding CanUserSort}" IsHovered="{TemplateBinding IsMouseOver}" IsPressed="{TemplateBinding IsPressed}" SeparatorVisibility="{TemplateBinding SeparatorVisibility}" SortDirection="{TemplateBinding SortDirection}">
							<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
						</Custom:DataGridHeaderBorder>
						<Thumb HorizontalAlignment="Left" x:Name="PART_LeftHeaderGripper">
							<Thumb.Style>
								<Style TargetType="{x:Type Thumb}">
									<Setter Property="Width" Value="8"/>
									<Setter Property="Background" Value="#00FFFFFF"/>
									<Setter Property="Cursor" Value="SizeWE"/>
									<Setter Property="Template">
										<Setter.Value>
											<ControlTemplate TargetType="{x:Type Thumb}">
												<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
											</ControlTemplate>
										</Setter.Value>
									</Setter>
								</Style>
							</Thumb.Style>
						</Thumb>
						<Thumb HorizontalAlignment="Right" x:Name="PART_RightHeaderGripper">
							<Thumb.Style>
								<Style TargetType="{x:Type Thumb}">
									<Setter Property="Width" Value="8"/>
									<Setter Property="Background" Value="#00FFFFFF"/>
									<Setter Property="Cursor" Value="SizeWE"/>
									<Setter Property="Template">
										<Setter.Value>
											<ControlTemplate TargetType="{x:Type Thumb}">
												<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
											</ControlTemplate>
										</Setter.Value>
									</Setter>
								</Style>
							</Thumb.Style>
						</Thumb>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type Custom:DataGridColumnHeader}">
		<Setter Property="Template" Value="{DynamicResource DataGridColumnHeaderControlTemplate}"/>
	</Style>
	<ControlTemplate x:Key="DataGridColumnHeaderControlTemplate" TargetType="{x:Type Custom:DataGridColumnHeader}">
		<Grid Margin="2,2,2,2">
			<Custom:DataGridHeaderBorder Background="{DynamicResource BrushControlBackgroundLight}" BorderBrush="{DynamicResource ImpassiveColor4}" BorderThickness="{DynamicResource ThicknessSize_1}" CornerRadius="{DynamicResource CornerRadiusSmall}" Padding="{TemplateBinding Padding}" IsClickable="{TemplateBinding CanUserSort}" IsHovered="{TemplateBinding IsMouseOver}" IsPressed="{TemplateBinding IsPressed}" SeparatorBrush="{DynamicResource ImpassiveColor4}" SeparatorVisibility="{TemplateBinding SeparatorVisibility}" SortDirection="{TemplateBinding SortDirection}">
				<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
			</Custom:DataGridHeaderBorder>
			<Thumb HorizontalAlignment="Left" x:Name="PART_LeftHeaderGripper">
				<Thumb.Style>
					<Style TargetType="{x:Type Thumb}">
						<Setter Property="Width" Value="8"/>
						<Setter Property="Background" Value="#00FFFFFF"/>
						<Setter Property="Cursor" Value="SizeWE"/>
						<Setter Property="Template">
							<Setter.Value>
								<ControlTemplate TargetType="{x:Type Thumb}">
									<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
								</ControlTemplate>
							</Setter.Value>
						</Setter>
					</Style>
				</Thumb.Style>
			</Thumb>
			<Thumb HorizontalAlignment="Right" x:Name="PART_RightHeaderGripper">
				<Thumb.Style>
					<Style TargetType="{x:Type Thumb}">
						<Setter Property="Width" Value="8"/>
						<Setter Property="Background" Value="#00FFFFFF"/>
						<Setter Property="Cursor" Value="SizeWE"/>
						<Setter Property="Template">
							<Setter.Value>
								<ControlTemplate TargetType="{x:Type Thumb}">
									<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
								</ControlTemplate>
							</Setter.Value>
						</Setter>
					</Style>
				</Thumb.Style>
			</Thumb>
		</Grid>
	</ControlTemplate>
	<Style x:Key="RowStyle" TargetType="{x:Type Custom:DataGridRow}">
        <Setter Property="AllowDrop" Value="True"/>
		<Setter Property="Template" Value="{DynamicResource DataGridRowControlTemplate}"/>
	</Style>
	<ControlTemplate x:Key="DataGridRowControlTemplate" TargetType="{x:Type Custom:DataGridRow}">
		<Border x:Name="DGR_Border" SnapsToDevicePixels="True" Background="{x:Null}" BorderThickness="{TemplateBinding BorderThickness}">
			<Custom:SelectiveScrollingGrid>
				<Custom:SelectiveScrollingGrid.RowDefinitions>
					<RowDefinition Height="*"/>
					<RowDefinition Height="Auto"/>
				</Custom:SelectiveScrollingGrid.RowDefinitions>
				<Custom:SelectiveScrollingGrid.ColumnDefinitions>
					<ColumnDefinition Width="Auto"/>
					<ColumnDefinition Width="*"/>
				</Custom:SelectiveScrollingGrid.ColumnDefinitions>
				<Custom:DataGridCellsPresenter Style="{DynamicResource DataGridCellsPresenterStyle}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Grid.Column="1" ItemsPanel="{TemplateBinding ItemsPanel}"/>
				<Custom:DataGridDetailsPresenter Visibility="{TemplateBinding DetailsVisibility}" Grid.Column="1" Grid.Row="1">
					<Custom:SelectiveScrollingGrid.SelectiveScrollingOrientation>
						<Binding Path="AreRowDetailsFrozen" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:DataGrid}}">
							<Binding.ConverterParameter>
								<Custom:SelectiveScrollingOrientation>Vertical</Custom:SelectiveScrollingOrientation>
							</Binding.ConverterParameter>
						</Binding>
					</Custom:SelectiveScrollingGrid.SelectiveScrollingOrientation>
				</Custom:DataGridDetailsPresenter>
				<Custom:DataGridRowHeader Style="{DynamicResource DataGridRowHeaderStyle}" Grid.RowSpan="2" Custom:SelectiveScrollingGrid.SelectiveScrollingOrientation="Vertical">
					<Custom:DataGridRowHeader.Visibility>
						<Binding Path="HeadersVisibility" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:DataGrid}}">
							<Binding.ConverterParameter>
								<Custom:DataGridHeadersVisibility>Row</Custom:DataGridHeadersVisibility>
							</Binding.ConverterParameter>
						</Binding>
					</Custom:DataGridRowHeader.Visibility>
				</Custom:DataGridRowHeader>
			</Custom:SelectiveScrollingGrid>
		</Border>
	</ControlTemplate>
	<Style x:Key="DataGridRowHeaderStyle" TargetType="{x:Type Custom:DataGridRowHeader}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type Custom:DataGridRowHeader}">
					<Grid>
						<Custom:DataGridHeaderBorder Background="#00000000" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}" IsHovered="{TemplateBinding IsMouseOver}" IsPressed="{TemplateBinding IsPressed}" IsSelected="{TemplateBinding IsRowSelected}" Orientation="Horizontal" SeparatorBrush="{TemplateBinding SeparatorBrush}" SeparatorVisibility="{TemplateBinding SeparatorVisibility}">
							<StackPanel Orientation="Horizontal">
								<ContentPresenter VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
								<Control Template="{Binding Path=ValidationErrorTemplate, RelativeSource={RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:DataGridRow}}}" SnapsToDevicePixels="False">
									<Control.Visibility>
										<Binding Path="(Validation.HasError)" RelativeSource="{RelativeSource FindAncestor, AncestorLevel=1, AncestorType={x:Type Custom:DataGridRow}}">
											<Binding.Converter>
												<BooleanToVisibilityConverter/>
											</Binding.Converter>
										</Binding>
									</Control.Visibility>
								</Control>
							</StackPanel>
						</Custom:DataGridHeaderBorder>
						<Thumb x:Name="PART_TopHeaderGripper" VerticalAlignment="Top">
							<Thumb.Style>
								<Style TargetType="{x:Type Thumb}">
									<Setter Property="Height" Value="8"/>
									<Setter Property="Background" Value="#00FFFFFF"/>
									<Setter Property="Cursor" Value="SizeNS"/>
									<Setter Property="Template">
										<Setter.Value>
											<ControlTemplate TargetType="{x:Type Thumb}">
												<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
											</ControlTemplate>
										</Setter.Value>
									</Setter>
								</Style>
							</Thumb.Style>
						</Thumb>
						<Thumb x:Name="PART_BottomHeaderGripper" VerticalAlignment="Bottom">
							<Thumb.Style>
								<Style TargetType="{x:Type Thumb}">
									<Setter Property="Height" Value="8"/>
									<Setter Property="Background" Value="#00FFFFFF"/>
									<Setter Property="Cursor" Value="SizeNS"/>
									<Setter Property="Template">
										<Setter.Value>
											<ControlTemplate TargetType="{x:Type Thumb}">
												<Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"/>
											</ControlTemplate>
										</Setter.Value>
									</Setter>
								</Style>
							</Thumb.Style>
						</Thumb>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<Style x:Key="DataGridCellsPresenterStyle" TargetType="{x:Type Custom:DataGridCellsPresenter}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type Custom:DataGridCellsPresenter}">
					<ItemsPresenter/>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>
	<Style x:Key="DataGridCellStyle" TargetType="{x:Type Custom:DataGridCell}">
		<Style.Triggers>
			<Trigger Property="IsSelected" Value="True">
				<Setter Property="Background" Value="{DynamicResource BrushControlBackgroundLightFocused}"/>
				<Setter Property="Foreground" Value="#FF000000"/>
			</Trigger>
		</Style.Triggers>
		<Setter Property="Template" Value="{DynamicResource DataGridCellControlTemplate}"/>
	</Style>
	<ControlTemplate x:Key="DataGridCellControlTemplate" TargetType="{x:Type Custom:DataGridCell}">
		<Border SnapsToDevicePixels="True" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
			<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" ContentTemplate="{TemplateBinding ContentTemplate}" VerticalAlignment="Center"/>
		</Border>
	</ControlTemplate>
</ResourceDictionary>